<%--
 *  File:    VisitPlanFeedbackDetail.jsp
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%

  String strTableName = "";
  String strModuleName = "SFE";
   String privilegeCode = "H0258";
  
	String contextPath = request.getContextPath();
%>

<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>VisitPlanFeedbackDetail</title>

<PageFlow:CheckPageFlow pageName="p_agreementbasedetail"/>
<%

/*int nYear=((Integer)pageContext.getAttribute("year")).intValue();
int nMonth=((Integer)pageContext.getAttribute("monthofyear")).intValue();
int nWeek=((Integer)pageContext.getAttribute("weekofmonth")).intValue();
int nDay=((Integer)pageContext.getAttribute("dayofweek")).intValue();
Calendar cal=Calendar.getInstance();
cal.clear();
cal.set(Calendar.YEAR,nYear);
cal.set(Calendar.MONTH,nMonth-1);
cal.set(Calendar.WEEK_OF_MONTH,nWeek);
cal.set(Calendar.DAY_OF_WEEK,nDay);

String[] weekLabelArrs=new String[]{"L_Sunday","L_Monday","L_Tuesday","L_Wednesday","L_Thursday","L_Friday","L_Saturday"};
String strFullDateFormat=label.getLabelName("L_FullDateFormat");
String strWeekShow=label.getLabelName(weekLabelArrs[nDay-1]);		
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(strFullDateFormat);
*/
String flag = (String)pageContext.getAttribute("flag");
if(flag == null) flag = new String("");

int nProcessID = -1;  
if (pageContext.getAttribute("processid") != null)
	nProcessID = ((Integer)pageContext.getAttribute("processid")).intValue();

     String viewflag = "";

     if(pageContext.getAttribute("viewflag") != null&&((String)pageContext.getAttribute("viewflag")).equals("view")) {

           viewflag = "view";
     }
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/Calendar.js"></script>

<script language="JavaScript">
function page_close()
{
	window.close();
}

function page_setfileid(num,id)
{
	var myform = eval("document.cform");
	var fileobj=eval("myform.detailattrachid"+num);
			
	if(!isEmpty(id))
	{
		fileobj.value=id;
	}
	else
	{
		fileobj.value=" ";
	}
}

function page_closedetail()
{
	var myform = eval("document.cform");
	myform.actionname.value = "close";
 	myform.target="_self";
 	isRunning = true;
 	myform.submit();
}

function page_confirm(num)
{

	emptyToNull(cform);

	if(  typeof(eval("top.message"))== "undefined") {
		  //alert(typeof(eval("window.top.opener.parent.message" )));
		  if(typeof(eval("window.top.opener.message" ))== "undefined") {
		     message = window.top.opener.parent.message;
		   }else{
		     message = window.top.opener.message;
		   }
		 }
		else {
		message = top.message;
		}

  
	var myform = eval("document.cform");

	
	for(i=0;i<Number(myform.numrows.value);i++)
	{
		var attrname=eval("myform.attrname"+i);
		var objtext=eval("myform.detailtext"+i);
		if(objtext!=null&& !isEmpty(objtext.value)) 
		{
		  if(objtext.value.length >200 ) 
		  {
			  alert(attrname.value+"<%=message.getMessageDesc("Input_Long")%>");
				return;
			}
		}
			
		var objnumber=eval("myform.detailnumber"+i);
		if(objnumber!=null && !isNumeric(objnumber.value))
		{
			alert(replaceString(message.Item("VALUE_MUST_BE_NUMBER"),"%s",attrname.value.replace("\'","'")));
			return;
		}
				
	  if(i<num)
	  {
			if(objnumber!=null && isEmpty(objnumber.value))
			{
				alert(replaceString(message.Item("VALUE_NOT_NULL"),"%s",attrname.value.replace("\'","'")));
				return;
			}
			
			//if(objtext!=null && isEmpty(objtext.value))
			//{
			//	alert(replaceString(message.Item("VALUE_NOT_NULL"),"%s",attrname.value.replace("\'","'")));
			//	return;
			//}
					
			var objselected=eval("myform.detailselect"+i);
			if(objselected!=null && isEmpty(objselected.value))
			{
				alert(replaceString(message.Item("VALUE_NOT_NULL"),"%s",attrname.value.replace("\'","'")));
				return;
			}
			
			var objattrach=eval("myform.detailattrachid"+i);
			if(objattrach!=null && isEmpty(objattrach.value))
			{
				alert(replaceString(message.Item("VALUE_NOT_NULL"),"%s",attrname.value.replace("\'","'")));
				return;
			}		
			
			if (myform.globalpccode.value == 112)
	    {						
		  
		    var objactionname = eval("myform.actionname"+i);
		    //��ƷVE20���ۼ۸���

			  if(objactionname != null && objactionname.value == '10340-100001220')
			  {
				  var objprice=eval("myform.detailnumber"+i);
				  if(objprice.value <15 || objprice.value >30)
				  {
					  alert("<%= message.getMessageDesc("RetailPrice_Must_Between_15_and_30")%>");
					  return;
				  }
				}
			  //��ƷVE20������ڼ��

			  if(objactionname != null && objactionname.value == '10341-100001220')
			  {								
				  var objdate=eval("myform.znovadetaildate"+i);
				  var Nowdate = new Date(); 
				  var nowyear = Nowdate.getYear();
				  var nowmonth = Nowdate.getMonth()+1;
				  var nowday = Nowdate.getDate(); 
				  var Nowdatestr = nowyear +'-'+nowmonth+'-'+nowday;
				  var oDate1= new Date(Date.parse(objdate.value.replace(/-/g,   "/")));   
				  var oDate2= new Date(Date.parse(Nowdatestr.replace(/-/g,   "/")));   								
				  if(oDate1 > oDate2)
				  {
				    alert("<%= message.getMessageDesc("proddate_error")%>");
				  	return;
				  }	
		  	}
			}						
		}
		
		var objscheck=eval("myform.sdetailcheck"+i);
		var objcheck=eval("myform.detailcheck"+i);
		if(objscheck!=null && objscheck.checked)
		{
			objcheck.value="Y";
		}
		else if(objscheck!=null && !objscheck.checked)
		{
			objcheck.value="N";
		}			
	}
	
	//var frm = document.cform;
	myform.pagename.value = "p_agreementbasedetail";
	myform.actionname.value = "save";
	myform.target = "_self";
	myform.submit();
}

</script>
</head>
<body>
	<form name="cform" method="post" action="../../Dispatcher">
    <input type="hidden" name="pagename" value="p_agreementbasedetail">
    <input type="hidden" name="actionname">
    <custom:hidden property="customerid"/>
    <custom:hidden property="contactid"/>
    <custom:hidden property="orgid"/>
    <custom:hidden property="year"/>
    <custom:hidden property="monthofyear"/>
    <custom:hidden property="weekofmonth"/>
    <custom:hidden property="dayofweek"/>
    <custom:hidden property="dayofmonth"/>
    <custom:hidden property="ishistory"/>	
    <custom:hidden property="processid"/>
    <custom:hidden property="zmylagreementid"/>
    <custom:hidden property="globalpccode"/>
    <custom:hidden name="visitplandetailinfo" property="planvisitdate"/>	
    <custom:hidden name="visitplandetailinfo" property="flag"/>
    <table width="100%" cellspacing="0" border="0" cellpadding="0">     



      <%   HashMap detailinfo=(HashMap)pageContext.getAttribute("zmylagreementinfo");
          	if(detailinfo==null)
          		detailinfo=new HashMap();
          	Integer oStatus=(Integer)detailinfo.get("status");

          	if(oStatus!=null && oStatus.intValue()==99)
          		pageContext.setAttribute("displayflag","view");
          			Date dActualStart=(Date)detailinfo.get("starttime");
          			Date dActualEnd=(Date)detailinfo.get("endtime");
          			String sActualStart="";
          			String sActualEdit="";
          		/*	if(dActualStart!=null)
          				sActualStart=sdf2Time.format(dActualStart);
          			if(dActualEnd!=null)
          				sActualEdit=sdf2Time.format(dActualEnd);*/
          	%>
    <%   Vector vBaseProcessDetails=(Vector)pageContext.getAttribute("basedetails");
             if(vBaseProcessDetails==null)
            	vBaseProcessDetails=new Vector();
        Vector vBasedetailValues=(Vector)pageContext.getAttribute("basedetailvalues");
        if(vBasedetailValues==null)
        	vBasedetailValues=new Vector();
            int num=0;
            if(vBaseProcessDetails.size()>0){
     %>       

       <tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
            <%
            Vector vAllFiles=(Vector)pageContext.getAttribute("allfiles");
            if(vAllFiles==null)
            	vAllFiles=new Vector();
            HashMap fileInfoMaps=new HashMap();
            for(int i=0;i<	vAllFiles.size();i++)
            {
            	HashMap oneFile=(HashMap)vAllFiles.get(i);
           		Integer oFileID=(Integer)oneFile.get("fileid");
           		if(oFileID!=null)
           		{
           			Vector vFiles=new Vector();
           			if(fileInfoMaps.containsKey(oFileID))
           			{
           				vFiles=(Vector)fileInfoMaps.get(oFileID);
           			}
           			vFiles.add(oneFile);
           			fileInfoMaps.put(oFileID,vFiles);
           		}
            }
            if(!fileInfoMaps.isEmpty())
           	{
           		Iterator iter=fileInfoMaps.keySet().iterator();
           		while(iter.hasNext())
           		{
           		Integer keyFile=(Integer)iter.next();
           		pageContext.setAttribute("file_"+keyFile,fileInfoMaps.get(keyFile));
           		}
           	}
           	fileInfoMaps.clear();
           	fileInfoMaps=null;
           	vAllFiles=null;
           	
           Vector vAllSourceTypes=(Vector)pageContext.getAttribute("allsourcetypes");
           if(vAllSourceTypes==null)
           	vAllSourceTypes=new Vector();
           	HashMap sourceTypeMaps=new HashMap();
           	for(int i=0;i<vAllSourceTypes.size();i++)
           	{
           		HashMap oneSourceTypes=(HashMap)vAllSourceTypes.get(i);
           		String strType=(String)oneSourceTypes.get("type");
           		if(strType!=null)
           		{
           			Vector vType=new Vector();
           			if(sourceTypeMaps.containsKey(strType))
           			{
           				vType=(Vector)sourceTypeMaps.get(strType);
           			}
           			vType.add(oneSourceTypes);
           			sourceTypeMaps.put(strType,vType);
           		}
           	}
           	if(!sourceTypeMaps.isEmpty())
           	{
           		Iterator iter=sourceTypeMaps.keySet().iterator();
           		while(iter.hasNext())
           		{
           		String keyType=(String)iter.next();
           		pageContext.setAttribute("sourcetypes_"+keyType,sourceTypeMaps.get(keyType));
           		}
           	}
           	sourceTypeMaps.clear();
           	sourceTypeMaps=null;
           	vAllSourceTypes=null;
           	
            for(int i=0;i<vBaseProcessDetails.size();i++){
            HashMap actionMap=(HashMap)vBaseProcessDetails.get(i);
            if(actionMap==null)
            		actionMap=new HashMap();
            HashMap mapValue=new HashMap();		
            if(i<vBasedetailValues.size())
            {
            	mapValue=(HashMap)vBasedetailValues.get(i);
            	pageContext.setAttribute("basedetailinfo",mapValue);
            }
            Integer odetailtype=(Integer)actionMap.get("contenttype");
            int ndetailtype	=0;
            if(	odetailtype!=null)
            	ndetailtype=odetailtype.intValue();
            Integer idxnum=new Integer(num);	
            %>
             <% if (num % 2 == 0){%>
             <tr > 
             <%}%>
          			<td width="180"><%=actionMap.get("agreementpropertyname")%></td>
          			<td >
          		 <%if(!viewflag.equals("view")){%>
                        <input type="hidden" name="attrname<%=num%>" value="<%=actionMap.get("agreementpropertyname")%>"/>
          				<input type="hidden" name="zmylagreementconfigdetailid<%=num%>" value="<%=actionMap.get("zmylagreementconfigdetailid")%>"/>
          				<input type="hidden" name="zmylagreementid<%=num%>" value="<%=actionMap.get("zmylagreementid")%>"/>

                        <custom:hidden  name="basedetailinfo"  property="zmylagreementbasedetailid"  colIndex="<%=idxnum%>"/>
          				<%if(ndetailtype==1){%>
          				<custom:text name="basedetailinfo" property="detailnumber" size="8" colIndex="<%=idxnum%>" />
          				<%}else if(ndetailtype==2){%>
          				<custom:textarea  name="basedetailinfo" property="detailtext" cols="80" rows="2"  colIndex="<%=idxnum%>"/>
          				
          				<%}else if(ndetailtype==3){
          					String strCheck="";
          					if("Y".equals(mapValue.get("detailcheck")))
          						strCheck="checked";
          					%>
          				<input type="checkbox" name="sdetailcheck<%=num%>" value="Y"  <%=strCheck%> class="normalradio"/>
          				<custom:hidden  name="basedetailinfo"  property="detailcheck"  colIndex="<%=idxnum%>"/>
          			<%}else if(ndetailtype==4){
          				String strSourceType=(String)actionMap.get("sourcetype");
          				strSourceType="sourcetypes_"+strSourceType;
          				%>
          			<custom:select name="basedetailinfo"  property="detailchoose"   optionsName="<%=strSourceType%>" optionValueKey="value" optionInnerTextKey="name"   colIndex="<%=idxnum%>"  defaultValueCost=" " defaultValue="--------" />
          			<%}
          			else if(ndetailtype==5){%>
          				<custom:hidden  name="basedetailinfo"  property="detailattrachid"   colIndex="<%=idxnum%>"/>
          				<iframe src="VisitdetailFileUpload.jsp?visitdetailfilesid=<custom:write  name="basedetailinfo"  property="detailattrachid" />&detailstatus=<custom:write  name="detailinfo"  property="status" />&detailno=<%=num%>&baseorskutype=base&<%= OvalTools.randomURL() %>" width="300" height="50" ></iframe>
          			<%}else if(ndetailtype==6){%>
          			<!-- 	<custom:text name="basedetailinfo" property="detaildate" size="10" dataType="date" colIndex="<%=idxnum%>" dataFormatName="dateformat" module="OGM" readonly="true"/>
          				<a onclick="show_calendar('cform.znovadetaildate<%=idxnum%>','MM-dd-yyyy')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
          			 -->
          				<custom:hidden  name="basedetailinfo"  property="detaildate"   colIndex="<%=idxnum%>"/>
          				<%@ include file="AgreementDetailDate.inc" %>
          			
          			
          			<%}else{%>
          			&nbsp;
          			<%}%>

                <%}else{%>
                      <input type="hidden" name="attrname<%=num%>" value="<%=actionMap.get("agreementpropertyname")%>"/>
          				<input type="hidden" name="zmylagreementconfigdetailid<%=num%>" value="<%=actionMap.get("zmylagreementconfigdetailid")%>"/>
          				<input type="hidden" name="zmylagreementid<%=num%>" value="<%=actionMap.get("zmylagreementid")%>"/>

                        <custom:hidden  name="basedetailinfo"  property="zmylagreementbasedetailid"  colIndex="<%=idxnum%>"/>
          				<%if(ndetailtype==1){%>
          				<custom:write name="basedetailinfo" property="detailnumber" />
          				<%}else if(ndetailtype==2){%>
          				<custom:textarea readonly="true" name="basedetailinfo" property="detailtext" cols="80" rows="2"  colIndex="<%=idxnum%>"/>

          				<%}else if(ndetailtype==3){
          					String strCheck="";
          					if("Y".equals(mapValue.get("detailcheck")))
          						strCheck="checked";
          					%>
          				<custom:write  name="basedetailinfo"  property="detailcheck" />
          			<%}else if(ndetailtype==4){
          				String strSourceType=(String)actionMap.get("sourcetype");
          				strSourceType="sourcetypes_"+strSourceType;
          				%>
          			<custom:select disabled="true" name="basedetailinfo"  property="detailchoose"   optionsName="<%=strSourceType%>" optionValueKey="value" optionInnerTextKey="name"   colIndex="<%=idxnum%>"  defaultValueCost=" " defaultValue="--------" />
          			<%}
          			else if(ndetailtype==5){%>
          				<custom:hidden  name="basedetailinfo"  property="detailattrachid"   colIndex="<%=idxnum%>"/>
          				<iframe src="VisitdetailFileUpload.jsp?visitdetailfilesid=<custom:write  name="basedetailinfo"  property="detailattrachid" />&detailstatus=<custom:write  name="detailinfo"  property="status" />&detailno=<%=num%>&baseorskutype=base&<%= OvalTools.randomURL() %>" width="300" height="50" ></iframe>
          			<%}else if(ndetailtype==6){%>
          			<!-- 	<custom:text name="basedetailinfo" property="detaildate" size="10" dataType="date" colIndex="<%=idxnum%>" dataFormatName="dateformat" module="OGM" readonly="true"/>
          				<a onclick="show_calendar('cform.znovadetaildate<%=idxnum%>','MM-dd-yyyy')"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
          			 -->
          				<custom:write  name="basedetailinfo"  property="detaildate" dataType="date" dataFormatName="dateformat"/>



          			<%}else{%>
          			&nbsp;
          			<%}%>
                <%}%>
                  </td>
          	<% if (num % 2 == 1){%>
          	</tr>
          	<%}%>
          	<%
          	num++;
          	}%>
          </table>
         </td>
       </tr>  
       <%}

           int numfrist=0;
           numfrist=+vBaseProcessDetails.size();
       %>

      <tr>
      	<td>
      		<table width="100%" cellspacing="0" cellpadding="0">
            <tr>
            	<td class="summary_top">
            	<input type="hidden" name="numrows" value="<%=num%>"/>
            	</td>
            </tr>
            <tr>
              <td class="td_center">
                <%if(!viewflag.equals("view")){%>
                  <%if(vBaseProcessDetails.size()>0 && (oStatus!=null || oStatus.intValue()==10)){%>

             			<a onclick="page_confirm(<%=numfrist %>);"><custom:button type="1" label="L_Save" imgsrc="new.gif" border="0" style="width:60"/></a>
             	 
                <%}%>
              <%}%>
              </td>
            </tr>
          </table>  
        </td>
      </tr>
    </table>
  </form>             	
</body>

</html>
	
